﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebService.Connect;
using System.Data.SqlClient;
using Model;
using System.Data;

namespace WebService.Datalayer
{
    public class DBHistoryBooking
    {
        Database db = new Database();
        SqlParameter[] listParameter;

        /// <summary>
        /// SelectHistoryBookingAll
        /// </summary>
        /// <returns></returns>
        public DataSet SelectHistoryBookingAll()
        {
            return db.GetDataset("sp_SelectHistoryBookingsAll");
        }

        public DataSet SelectHistoryBookingByDateTime(string from, string to)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("BookingDateFrom",from),
                 new SqlParameter("BookingDateTo", to),
            };
            return db.GetDataSetWithParameter("sp_SelectHistoryBookings", listParameter);
        
        }

        /// <summary>
        /// SelectHistoryBookingsByAndHistoryBookingID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectHistoryBookingsByAndHistoryBookingID(HistoryBookings obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@HistoryBookingID", obj.HistoryBookingID),
            };
            return db.GetDataSetWithParameter("sp_SelectHistoryBookingsByAndHistoryBookingID", listParameter);
        }

        /// <summary>
        /// DeleteHistoryBooking
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int DeleteHistoryBooking(HistoryBookings  obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@HistoryBookingID", obj.HistoryBookingID),
            };
            return db.ExcuteQueryWithParamater("sp_DeleteHistoryBooking", listParameter);
        }

        /// <summary>
        ///  SelectHistoryBookingByBookingID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectHistoryBookingByBooking(HistoryBookings obj)
        {
            listParameter = new SqlParameter[]
            { 
                new SqlParameter("@BookingID", obj.BookingID),
            };
            return db.GetDataSetWithParameter("sp_SelectHistoryBookingsByAndBookingID",listParameter);
        }

        /// <summary>
        ///  SelectHistoryBookingByOldMenuID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectHistoryBookingByMenuID(HistoryBookings obj)
        {
            listParameter = new SqlParameter[]
            { 
                new SqlParameter("@OldMenuID", obj.MenuID),
            };
            return db.GetDataSetWithParameter("sp_SelectHistoryBookingsByAndOldMenuID", listParameter);
        }

        /// <summary>
        /// InsertHistoryBooking
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int InsertHistoryBooking(HistoryBookings obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@HistoryBookingID", obj.HistoryBookingID),
                new SqlParameter("@BookingID", obj.BookingID),
                new SqlParameter("@MenuID", obj.MenuID),
                new SqlParameter("@Reason", obj.Reason),
                new SqlParameter("@IsDeleted", obj.IsDeleted),
                new SqlParameter("@BookingNumber", obj.BookingNumber),
            };
            return db.ExcuteQueryWithParamater("sp_InsertHistoryBooking", listParameter);
        }
        
        /// <summary>
        /// UpdateHistoryBooking
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int UpdateHistoryBooking(HistoryBookings obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@BookingID", obj.BookingID),
                new SqlParameter("@MenuID", obj.MenuID),
                new SqlParameter("@Reason", obj.Reason),
                new SqlParameter("@IsDeleted", obj.IsDeleted),
                new SqlParameter("@BookingNumber", obj.BookingNumber),
                new SqlParameter("@HistoryBookingID", obj.HistoryBookingID),
            };
            return db.ExcuteQueryWithParamater(" sp_UpdateHistoryBooking", listParameter);
        }
    }
}